package blt.app_core.api.journey;

import java.util.List;

import blt.app_core.api.base.bean.OAuth;
import blt.app_core.api.base.bean.State;
import blt.app_core.api.base.callback.ComBack;
import blt.app_core.api.base.callback.StateCallback;
import blt.app_core.api.impl.BaseImpl;
import blt.app_core.api.journey.bean.AppealInfo;
import blt.app_core.api.journey.bean.Travel;
import blt.app_core.api.journey.bean.TravelDetail;
import blt.app_core.api.login.bean.Cookie;
import blt.app_core.log.Logger;
import blt.app_core.utils.UriProdiver;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by xgp
 * on 2017/6/22.
 */

public class JourneyImpl extends BaseImpl<JourneyService> implements JourneyApi {


    @Override
    public Travel getTravel(int page, int size, boolean isInvoice, boolean isRefund) {
        builderLoginRequest();
        if (isInvoice) {
            mService.getTravel(page, size, isInvoice).enqueue(new StateCallback<Travel>() {
                @Override
                protected void onSuccess(Travel data) {
                    notifyClients(JourneyApi.class, JourneyApi.onTravel, data);
                }
            });
            return null;
        }
        if(isRefund){
            mService.getRefundTravel(page, size, isRefund).enqueue(new StateCallback<Travel>() {
                @Override
                protected void onSuccess(Travel data) {
                    notifyClients(JourneyApi.class, JourneyApi.onRefundTravel, data);
                }
            });
            return null;
        }
        mService.getTravel(page, size).enqueue(new StateCallback<Travel>() {
            @Override
            protected void onSuccess(Travel data) {
                notifyClients(JourneyApi.class, JourneyApi.onTravel, data);
            }
        });
        return null;
    }


    @Override
    public TravelDetail getDetail(int id) {
        builderLoginRequest();
        mService.getTravelDetail(id).enqueue(new StateCallback<TravelDetail>() {
            @Override
            protected void onSuccess(TravelDetail data) {
                notifyClients(JourneyApi.class, JourneyApi.onDetail, data);
            }
        });
        return null;
    }


    @Override
    public void snatchRedpacket(int travelOrderId) {
        builderLoginRequest();
        mService.snatchRedpacket(travelOrderId).enqueue(new StateCallback<String>() {
            @Override
            protected void onSuccess(String data) {
                notifyClients(JourneyApi.class, JourneyApi.onRedPackage, data);
            }
        });


    }

    @Override
    public void addComplaint(String url, int travelOrderId, String appealDetail, String pic1, String pic2, String pic3, String contact, String phone, String reason) {
        mService.addComplaint(url, travelOrderId, appealDetail, pic1, pic2, pic3, contact, phone, reason).enqueue(new Callback<State>() {
            @Override
            public void onResponse(Call<State> call, Response<State> response) {
                notifyClients(JourneyApi.class, JourneyApi.onComplaintSuccess);
            }

            @Override
            public void onFailure(Call<State> call, Throwable t) {

            }
        });

    }

    @Override
    public void getAppeal(int page, int size) {
        mService.getAppeal(page, size).enqueue(new ComBack<AppealInfo>() {
            @Override
            protected void onSuccess(List<AppealInfo> data) {
                notifyClients(JourneyApi.class, JourneyApi.onComplaint, data);
            }
        });
    }

    @Override
    public void getAppealDetail(int appealId) {
        mService.getAppealDetail(appealId).enqueue(new StateCallback<AppealInfo>() {
            @Override
            protected void onSuccess(AppealInfo data) {

            }
        });
    }

}